include config.do

#delimit ;

cap log close ;
log using $logdir/06.01.leave_one_out_$date.log, replace;

global othdate = "2023-08-25" ;

insheet using $supportdir/bias_scatter_barrons_byyear_$othdate.csv, clear ;
end
postfile support state MSE beta se tstat using $supportdir/leave_one_out_$date.dta, replace; 

levelsof state, local(statelist);
tab state ; 

foreach st in `statelist' { ;
	/* First, run a regression of bias on missing_diff, excluding a state */
	di "******************************************" ;
	di "**************** STATE `st' **************" ;
	di "******************************************" ;
	reg bias missing_diff i.state i.year i.grad_year if state != `st' [weight=in_n], nocons;
	local beta = _b[missing_diff];
	local se = _se[missing_diff];
	local tstat = `beta'/`se' ;
	predict bias_pred, xb;
	gen error_sq = (bias - bias_pred)^2 ;
	summ error_sq ; 
	post support (`st') (r(mean)) (`beta') (`se') (`tstat');
	drop bias_pred error_sq ;
};

postclose support ;

use $supportdir/leave_one_out_$date.dta, clear ;

sum MSE, d;
sum beta, d;

list beta se tstat ; 
di "***** AVERAGE MEAN SQUARED ERROR:   " r(mean) ;
